package com.example.zhang;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;

import java.util.ArrayList;

public class ListActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        ListView listview = findViewById(R.id.mylist);
        ProgressBar progressBar = findViewById(R.id.progressBar);
        Handler handler = new Handler(){
            @Override
            public void handleMessage (@NonNull Message msg){
              if (msg.what == 1) {
                ArrayList<String> sites = (ArrayList<String>) msg.obj;
                ListAdapter adapter = new ArrayAdapter<String>(ListActivity.this, android.R.layout.simple_list_item_1, sites);
                listview.setAdapter(adapter);

                progressBar.setVisibility(View.GONE);
                listview.setVisibility(View.VISIBLE);
              }
              super.handleMessage(msg);
            }
        };
        MylistActivity_button mylistActivity_button =new MylistActivity_button();
        mylistActivity_button.setHandler(handler);
        Thread t =new Thread(mylistActivity_button);
        t.start();

    }
}